package nku.csc364.updatedatabase;

import nku.csc364.R;
import nku.csc364.databasehelper.DataHelper;
import nku.csc364.updatedatabase.UpdateDatabaseProductActivity.MyOnProductSelectedListener;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;

public class UpdateDatabaseQOHActivity extends Activity{
	Spinner qohItem; 
	EditText qohQuantity; 
	DataHelper dh = null; 
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.qohupdate);
        
        qohItem = (Spinner)findViewById(R.id.qohSpinner1);
        qohQuantity = (EditText)findViewById(R.id.qohEditText1);
        
        dh = DataHelper.getDataHelper(this);
        setItemSpinner();
        qohItem.setPrompt("Select...");
    }
	  
	private void clean(){
		 qohQuantity.setText(""); 
		 this.qohItem.setSelection(0);
	}
    
    private void setItemSpinner() {
		qohItem.setAdapter(getItemAdapter());
	}
	
	  @SuppressWarnings("unchecked")
		public ArrayAdapter<CharSequence> getItemAdapter(){
				    @SuppressWarnings("rawtypes")
					ArrayAdapter itemAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, dh.selectAllItems());	 
			        itemAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			        itemAdapter.insert(" ", 0);
			        return itemAdapter;
		}
	  
		public  void openCategory(View view){
			Intent launchCategory = new Intent(this, UpdateDatabaseCategoryActivity.class);
			startActivityForResult(launchCategory, 1);
		}
		
		public void openItem(View view){
			Intent launchItem = new Intent(this, UpdateDatabaseItemActivity.class);
			startActivityForResult(launchItem, 1);
		}
		
		public void openProduct(View view){
			Intent launchProduct = new Intent(this, UpdateDatabaseProductActivity.class);
			startActivityForResult(launchProduct, 1);
		}
		
		public void openQOH(View view){
			Intent launchQOH = new Intent(this, UpdateDatabaseQOHActivity.class);
			startActivityForResult(launchQOH, 1);
		}
		
		public void openSupplier(View view){
			Intent launchSupplier = new Intent(this, UpdateDatabaseSupplierActivity.class);
			startActivityForResult(launchSupplier, 1);
		}
    
	public void doSubmitQOH(View view){
		dh.updateQuantity(qohItem.getSelectedItem().toString(), 
				Integer.parseInt(qohQuantity.getText().toString()));
		clean();
	}
	
	public void doFireQOH(){
		//TODO
	}
}
